.macro cbm.and       rd, rs1, rs2, es
.insn r CUSTOM_0, 0, \es*32, \rd, \rs1, \rs2
.endm

.macro cbm.or        rd, rs1, rs2, es
.insn r CUSTOM_0, 1, \es*32, \rd, \rs1, \rs2
.endm

.macro cbm.xor       rd, rs1, rs2, es
.insn r CUSTOM_0, 2, \es*32, \rd, \rs1, \rs2
.endm

.macro cbm.sll        rd, rs1, rs2, es
.insn r CUSTOM_0, 3, \es*32, \rd, \rs1, \rs2
.endm

.macro cbm.srl       rd, rs1, rs2, es
.insn r CUSTOM_0, 4, \es*32, \rd, \rs1, \rs2
.endm


.macro cbm.andi       rd, rs1, imm, es
.insn i CUSTOM_1, 0, \rd, \rs1, (\imm & 0x3ff)+1024*(\es & 1)-2048*((\es >> 1) & 1)
.endm

.macro cbm.ori        rd, rs1, imm, es
.insn i CUSTOM_1, 1, \rd, \rs1, (\imm & 0x3ff)+1024*(\es & 1)-2048*((\es >> 1) & 1)
.endm

.macro cbm.xori       rd, rs1, imm, es
.insn i CUSTOM_1, 2, \rd, \rs1, (\imm & 0x3ff)+1024*(\es & 1)-2048*((\es >> 1) & 1)
.endm

.macro cbm.slli       rd, rs1, imm, es
.insn i CUSTOM_1, 3, \rd, \rs1, (\imm & 0x3ff)+1024*(\es & 1)-2048*((\es >> 1) & 1)
.endm

.macro cbm.srli       rd, rs1, imm, es
.insn i CUSTOM_1, 4, \rd, \rs1, (\imm & 0x3ff)+1024*(\es & 1)-2048*((\es >> 1) & 1)
.endm

.macro cbm.refresh    rd, rs1
.insn i CUSTOM_1, 7, \rd, \rs1, 0
.endm



.macro cbm.prg       imm
.insn r CUSTOM_2, 0, \imm, x0, x0, x0
.endm

.macro cbm.s2r       rd, imm
.insn r CUSTOM_2, 1, \imm, \rd, x0, x0
.endm

.macro cbm.r2s       rs1, imm
.insn r CUSTOM_2, 2, \imm, x0, \rs1, x0
.endm


